package first.group.ssh.packet;

import java.nio.ByteBuffer;

public abstract class Packet {
    private final int type;
    
    public Packet(int type) {
        this.type = type;
    }
    
    public int getType() {
        return type;
    }
    
    public abstract void write(ByteBuffer buffer);
    
    public byte[] toByteArray() {
        var buffer = ByteBuffer.allocate(65535);
        write(buffer);
        buffer.flip();
        var arr = new byte[buffer.limit()];
        buffer.get(arr);
        return arr;
    }
}
